<template>
  <h3>autoComplete 组件示例</h3>

  <f-auto-complete 
    v-model:value="value"
    :options="options"
    style="width: 200px"
    @select="onSelect"
    @search="onSearch" />

  <f-auto-complete 
    v-model:value="value"
    :options="options"
    style="width: 200px"
    @select="onSelect"
    @search="onSearch">
    <template #option="item">
      {{ item }}
    </template>
  </f-auto-complete>

</template>

<script setup lang="ts">
import { defineComponent, ref, watch } from 'vue';

interface MockVal {
  value: string;
}
const mockVal = (str: string, repeat = 1): MockVal => {
  return {
    value: str.repeat(repeat),
  };
};

const value = ref('');
const options = ref<MockVal[]>([]);
const onSearch = (searchText: string) => {
  console.log('searchText');
  options.value = !searchText
    ? []
    : [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)];
};
const onSelect = (value: string) => {
  console.log('onSelect', value);
};
watch(value, () => {
  console.log('value', value.value);
});

</script>

<style lang="scss">

</style>
